package com.forum.core.filter;

import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;

public class LoginUserInfoFilter
    implements Filter
{

    public LoginUserInfoFilter()
    {
        logonPage = "/logon.jsp";
    }

    public void destroy()
    {
    }

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain)
        throws IOException, ServletException
    {
        HttpServletRequest request = (HttpServletRequest)servletRequest;
        HttpServletResponse response = (HttpServletResponse)servletResponse;
        String nodename = request.getRequestURI().substring(request.getRequestURI().lastIndexOf("/") + 1);
        if(nodename.indexOf("portal") == -1 && nodename.indexOf("info-pub") != 0 && nodename.indexOf("infomation.jsp") != 0 &&nodename.indexOf("download") == -1 && nodename.indexOf("login!intro.action") <= -1)
        {
            boolean login = nodename.indexOf("login.action") > -1 || nodename.indexOf("login.jsp") > -1;
            HttpSession session = request.getSession();
            /*UserInfo loginUser = (UserInfo)session.getAttribute("loginUser");
            if(loginUser == null && !login)
            {
                RequestDispatcher dispatcher = request.getRequestDispatcher(logonPage);
                dispatcher.forward(request, response);
                return;
            }*/
        }
        chain.doFilter(servletRequest, servletResponse);
    }

    public void init(FilterConfig arg0)
        throws ServletException
    {
        logonPage = arg0.getInitParameter("logonPage");
    }

    String logonPage;
}
